package com.song.su.controller;


import com.song.su.mapper.BookDetailMapper;
import com.song.su.mapper.CommentMapper;
import com.song.su.model.BookDetail;
import com.song.su.model.CommentUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;


@Controller
public class BookController {
    @Autowired
    CommentMapper commentMapper;


    @Autowired
    BookDetailMapper bookDetailMapper;

    @GetMapping("/book")
    public String publish(@RequestParam(name="isbn") String isbn,
            Model model){
        // 所有可能的抛空指针用try
        try {
            BookDetail bookDetail = bookDetailMapper.findBook(isbn);
           List<CommentUser> commentUser= commentMapper.findByIsbn(isbn);
            model.addAttribute("book",bookDetail);
            model.addAttribute("commentUser",commentUser);
        } catch (Exception e) {
            e.printStackTrace();
        }

//        System.out.println(commentUser.get(0).getLikecount());



        return "book";
    }
}
